local class = require('middleclass')
local utils = require('utils.utils')
local List = require('utils.list')
local Container = class('Container')

function Container:initialize()
    self.children = List:new()
end

function Container:add(object)
    self.children:append(object)
end

function Container:remove(pos)
    self.children:remove(object)
end

function Container:find(uid)
    return self.children:filter(
        function(i, v)
            return v.uid == uid
        end
    )
end

function Container:count()
    return self.children:size()
end

function Container:clear()
    self.children:foreach(
        function(i, v)
            utils.call(v.destroy, v)
        end
    )
    self.children:clear()
end

return Container
